//
//  WSQuestionDetailCell.m
//  WisdomStar
//
//  Created by 谭飞 on 2018/11/1.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "WSQuestionDetailCell.h"

#import "QuestionDetailInfo.h"

@interface WSQuestionDetailCell ()

@property (weak, nonatomic) IBOutlet UIImageView *headImage;

@property (weak, nonatomic) IBOutlet UILabel *nameLab;

@property (weak, nonatomic) IBOutlet UILabel *timeLab;

@property (weak, nonatomic) IBOutlet UILabel *contentLab;

@property (weak, nonatomic) IBOutlet UILabel *likeCountLab;

@property (weak, nonatomic) IBOutlet UIButton *acceptBtn;

@property (weak, nonatomic) IBOutlet UIButton *replyBtn;

@property (weak, nonatomic) IBOutlet UIButton *likeBtn;

@property (weak, nonatomic) IBOutlet UILabel *tipLabel;

@end

@implementation WSQuestionDetailCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self.headImage setCorners:UIRectCornerAllCorners cornerRadius:self.headImage.xmg_height/2];
    [self.acceptBtn setRoundBorder:kThemeGreenColor radius:self.acceptBtn.xmg_height/2];
    [self.replyBtn setRoundBorder:kThemeGreenColor radius:self.replyBtn.xmg_height/2];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - Actions

// 采纳
- (IBAction)acceptBtnClick:(id)sender {
    if (self.didAcceptedCallback) {
        self.didAcceptedCallback(self.tipLabel);
    }
}

// 回复
- (IBAction)replyBtnClick:(id)sender {
    if (self.replyCallback) {
        self.replyCallback();
    }
}

// 点赞
- (IBAction)likeBtnClick:(id)sender {
    if (self.didLikedCallback) {
        self.didLikedCallback(self.likeBtn, self);
    }
}

#pragma mark - Setter

- (void)setDetail:(QuestionDetailInfo *)detail {
    _detail = detail;
    self.replyBtn.hidden = !detail.is_landlord;
    self.acceptBtn.hidden = !detail.is_landlord;
}

- (void)setMessage:(WSMessageInfo *)message {
    _message = message;
    [self.headImage imageWithCompleteUrl:message.head defaultImage:nil];
    self.nameLab.text = message.uname;
    self.timeLab.text = message.create_at;
    self.contentLab.text = message.msg;
    self.likeBtn.selected = message.zan > 0;
    self.likeCountLab.hidden = message.zan == 0;
    self.likeCountLab.text = [NSString stringWithFormat:@"%ld",(long)message.zan];
    
}

@end
